package com.spirngcloud.alibabasentinelratelimiting.controller.mq.util.TopicStartegy;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @version V1.0
 * @Author 宋聚智
 * @Date 2019/10/24 10:48
 * @description
 * @Modify By：
 * @ModifyTime： 2019/10/24
 * @Modify marker：
 **/
//topic 策略
@Configuration
public class TopicExchangeConfig {
    @Bean(name = "myTopicExchange")
    TopicExchange getTopicExchange() {
        return new TopicExchange("My-Topic-Exchange");
    }


    //将myFirstQueue对应的Queue绑定到此TopicExchange，并指定路由建为”routingKey.#“
    //即：次Exchange中，路由键以"routingKey."开头的Queue将被匹配到
    @Bean
    Binding bindingQueueOneToTopicExchange(@Qualifier("myFirstQueue") Queue myFirstQueue,
                                           @Qualifier("myTopicExchange") TopicExchange myTopicExchange) {
    return BindingBuilder.bind(myFirstQueue).to(myTopicExchange).with("routingKey.#");
    }


    //将myTwoQueue对应的Queue绑定到此topicExchange,并指定路由键为"#.top"
    //即此exchange中，路由键以“.topic”结尾的Queue将被匹配到
    @Bean
    Binding binddingQueueTwoToTopicExchagne(@Qualifier("myTwoQueue") Queue myTwoQueue,
                                             @Qualifier("myTopicExchange") TopicExchange myTopicExchange){
        return BindingBuilder.bind(myTwoQueue).to(myTopicExchange).with("#.topic");
    }

    @Bean
    Binding binddingQueueThreeToTopicExchagne(@Qualifier("myThreeQueue") Queue myThreeeQueue,
                                            @Qualifier("myTopicExchange") TopicExchange myTopicExchange){
        return BindingBuilder.bind(myThreeeQueue).to(myTopicExchange).with("#");
    }
}
